package com.comac.tasks.manager.app.exception;

import com.alibaba.cola.exception.BizException;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author wfb
 */
@RestControllerAdvice
public class ExceptionsHandler {
    /**
     * 业务异常
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(BizException.class)
    public R bizExceptionHandler(BizException ex) {
        return R.failed(ex.getMessage());
    }

    /**
     * 参数转换异常拦截
     * @param ex
     * @return
     */
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public R exceptionHandler(HttpMessageNotReadableException ex) {
        return R.failed("参数格式异常！");
    }
}
